using System;
using System.Collections.Generic;
using System.Text;
using Pacman.Simulator;

namespace Pacman.Implementations
{
	public class DangerPac : BasePacman
	{
		private bool init = false;		

		public DangerPac() : base("DangerPac","1") {			
		}
		
		public override Direction Think(GameState gs) {
			if( !init ) {				
				init = true;
				/*gs.PacmanDead += new EventHandler(delegate(object sender, EventArgs e) {
					gs.PausePlay();
					//Console.WriteLine(" ======== PACMAN DEAD ======== ");
				});
				gs.Red.SetPosition(91, 13, Direction.Right);
				gs.Pacman.SetPosition(147, 21, Direction.Down);
				gs.Blue.SetPosition(179, 37, Direction.Left);
				gs.Blue.IsEntered();
				gs.PausePlay();*/
			}			
			Prediction p = new Prediction(gs, 15);
			return Direction.None;
			/*if( inverseCount > 0 ) inverseCount--;
			Prediction p = new Prediction(gs, 10);
			StateInfo.NearestPillPath pillPath = StateInfo.NearestPill(gs.Pacman.Node, gs);
			Direction bestDirection = gs.Pacman.Direction;
			if( pillPath.PathInfo != null ) {				
				if( !StateInfo.IsInverse(pillPath.PathInfo.Direction, bestDirection)
					|| !gs.Pacman.Node.GetNode(bestDirection).Walkable ) {
					bestDirection = pillPath.PathInfo.Direction;
				} else if( inverseCount == 0 ) {
					bestDirection = pillPath.PathInfo.Direction;
					inverseCount = 10;
				}
			}
			bestDirection = p.LeastDangerous();
			if( p.PacDanger[(int)bestDirection] >= 0.4 ) {
				bestDirection = p.LeastDangerous();
			}
			return bestDirection;*/
			//Console.WriteLine("Pacman: " + gs.Pacman.Node);
			foreach( Direction d in p.PossibleDirections ) {
				//Console.Write(d + ",");
			}
			//Console.Write(" -- Orig: ");
			foreach( Node node in gs.Pacman.Node.PossibleDirections ) {
				//Console.Write(gs.Pacman.Node.GetDirection(node) + ",");
			}

			if( p.PossibleDirections.Count == 1 ) {
				//Console.WriteLine("");
				return p.PossibleDirections[0];
			}
			StateInfo.PillPath pillPath = StateInfo.NearestPill(gs.Pacman.Node, gs);
			if( pillPath.PathInfo != null ) {
				//Console.Write(" -- Shortest: " + pillPath.PathInfo.Direction + " @ " + pillPath.PathInfo.Distance);
				foreach( Direction d in p.PossibleDirections ) {
					if( d == pillPath.PathInfo.Direction ) {
						//Console.WriteLine(":: Pill hunter decision: " + d);			
						return d;
					}
				}
			}
			//Console.WriteLine("");
			return p.PossibleDirections[0];
		}
	}
}
